package com.peenongsaban.freelance.service;

import java.util.Vector;

import com.peenongsaban.freelance.bean.AptitudeTypeBean;
import com.peenongsaban.freelance.bean.PostJobBean;
import com.peenongsaban.freelance.bean.RequestFreelanceBean;
import com.peenongsaban.freelance.bean.RequestJobBean;
import com.peenongsaban.freelance.dao.MyJobDAO;
import com.peenongsaban.freelance.dao.impl.MyJobDAOImpl;
import com.peenongsaban.freelance.model.MyJobModel;
import com.peenongsaban.freelance.model.PageModel;
import com.peenongsaban.freelance.utils.ConstantUtils;
/*
 * List my post job
 * List my request job
 * Show paging of my post job
 * Show paging of my request job
 * Show all my post job
 * Show all my request job
 */
public class MyJobService {
	public Vector<PostJobBean> getListMyPostJob(MyJobModel model) {
		Vector<PostJobBean> vec = new Vector<PostJobBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		vec = dao.listMyPostJob(model);
		return vec;
	}

	public Vector<RequestJobBean> getListMyRequestJob(MyJobModel model) {
		
		Vector<RequestJobBean> vec = new Vector<RequestJobBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		vec = dao.listMyRequestJob(model);
		return vec;
	}

	public Vector<PostJobBean> getListLastPostJob() {
		Vector<PostJobBean> list = new Vector<PostJobBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		list = dao.listLastPostJob();
		return list;
	}

	public PageModel pagingPostJob(MyJobModel model) {
		PageModel page = new PageModel();
		MyJobDAO dao = new MyJobDAOImpl();
		int itemList = ConstantUtils.LIMIT_PAGING_MY_POST_JOB;
		int size = dao.countLlistMyPostJob(model);
		int totalPage = (size / itemList);
		if (size % itemList != 0) {
			totalPage++;
		}
		if (model.getPagePostJob().getPageCurrentNo() == 0) {
			page.setPageCurrentNo(1);
		} else {
			page.setPageCurrentNo(model.getPagePostJob().getPageCurrentNo());
		}
		page.setTotalPage(totalPage);
		page.setListTotalRow(size);
		page.setListLastRowNo(totalPage);
		return page;
	}

	public PageModel pagingRequstJob(MyJobModel model) {
		PageModel page = new PageModel();
		MyJobDAO dao = new MyJobDAOImpl();
		int itemList = ConstantUtils.LIMIT_PAGING_MY_REQUEST_JOB;
		int size = dao.countLlistMyRequestJob(model);
		int totalPage = (size / itemList);
		if (size % itemList != 0) {
			totalPage++;
		}
		if (model.getPageRequestJob().getPageCurrentNo() == 0) {
			page.setPageCurrentNo(1);
		} else {
			page.setPageCurrentNo(model.getPageRequestJob().getPageCurrentNo());
		}
		page.setTotalPage(totalPage);
		page.setListTotalRow(size);
		return page;
	}
	
	public int allMyPostJob(String idCard){
		MyJobDAO dao = new MyJobDAOImpl();
		int total = dao.countAllMyPostJob(idCard);
		return total;
	}
	
	public int allMyRequestJob(String idCard){
		MyJobDAO dao = new MyJobDAOImpl();
		int total = dao.countAllMyRequestJob(idCard);
		return total;
	}
	
	public Vector<RequestJobBean> getListRequestJobByRequestStatus(String idCard){
		Vector<RequestJobBean> vec = new Vector<RequestJobBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		vec = dao.listRequestJobByRequestType(idCard, ConstantUtils.STATUS_REQUEST_OF_REQUEST_JOB);
		return vec;
	}
	
	public Vector<RequestJobBean> getListRequestJobByConfirmStatus(String idCard){
		Vector<RequestJobBean> vec = new Vector<RequestJobBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		vec = dao.listRequestJobByRequestType(idCard, ConstantUtils.STATUS_APPROVED_OF_REQUEST_JOB);
		return vec;
	}
	
	public Vector<RequestJobBean> getListRequestJobByRejectStatus(String idCard){
		Vector<RequestJobBean> vec = new Vector<RequestJobBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		vec = dao.listRequestJobByRequestType(idCard, ConstantUtils.STATUS_DISAPPROVED_OF_REQUEST_JOB);
		return vec;
	}
	
	public Vector<RequestFreelanceBean> getlistBeEmployed(String idCard){
		Vector<RequestFreelanceBean> vec = new Vector<RequestFreelanceBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		vec = dao.listBeEmployed(idCard);
		return vec;
	}
	
	public Vector<AptitudeTypeBean> getListJobCategoryJob() {
		Vector<AptitudeTypeBean> vec = new Vector<AptitudeTypeBean>();
		MyJobDAO dao = new MyJobDAOImpl();
		vec = dao.listCategoryJob();
		return vec;
	}
}
